//
//  NRWFilterColorCell.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/12.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWFilterColorCell.h"

@implementation NRWFilterColorCell
{
    UIImageView *_mColorImageView;
    UILabel *_mColorNameLabel;
}

- (void)setColorCode:(NSString *)colorCode {
    
    _colorCode = colorCode;
    
    _mColorImageView.backgroundColor = getColor(colorCode);
    
    if ([[colorCode lowercaseString] hasSuffix:@"ffffff"]) {
        
        _mColorImageView.layer.borderColor = getColor(@"#B2B2B2").CGColor;
        _mColorImageView.layer.borderWidth = 0.5;
    } else {
        _mColorImageView.layer.borderColor = UIColor.clearColor.CGColor;
        _mColorImageView.layer.borderWidth = 0.0;
    }
    
    if ([colorCode isEqualToString:@"#ABCDEF"]) {
        _mColorImageView.backgroundColor = [UIColor whiteColor];
        _mColorImageView.image = getImage(@"icon_other_color");
    } else {
        _mColorImageView.image = nil;
    }
}

- (void)setColorName:(NSString *)colorName {
    
    _colorName = colorName;
    
    _mColorNameLabel.text = colorName;
}

- (void)setIsSelect:(BOOL)isSelect {
    
    _isSelect = isSelect;
    
    _mColorNameLabel.textColor = isSelect? mainColor(): mainFontColor();
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = self.contentView.backgroundColor = getColor(@"#F9F9F9");
        self.opaque = self.contentView.opaque = YES;
        
        _mColorImageView = [[UIImageView alloc] init];;
        _mColorImageView.opaque = YES;
        _mColorImageView.backgroundColor = [UIColor whiteColor];
        _mColorImageView.layer.cornerRadius = 15;
        [self.contentView addSubview:_mColorImageView];
        
        _mColorNameLabel = [[UILabel alloc] init];
        _mColorNameLabel.textColor = mainFontColor();
        _mColorNameLabel.font = getThemeFont(13);
//        _mColorNameLabel.backgroundColor = getColor(@"#F9F9F9");;
//        _mColorNameLabel.opaque = YES;
        _mColorNameLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_mColorNameLabel];
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    _mColorImageView.frame = CGRectMake(5, 0, self.viewWidth - 10, self.viewWidth - 10);
    _mColorNameLabel.frame = CGRectMake(0, CGRectGetMaxY(_mColorImageView.frame), self.viewWidth, self.viewHeight - 30);
}

@end
